
#将.doc文件转化为.docx文件
from win32com import client as wc
import os

def doc_to_docx(doc_path,docx_path):
    word = wc.Dispatch('Word.Application')
    doc = word.Documents.Open(doc_path)  # 目标路径下的文件
    doc.SaveAs(docx_path, 12, False, "", True, "", False,
               False, False, False)  # 转化后路径下的文件
    doc.Close()
    word.Quit()


def read_doc(doc_path:str):
    if not doc_path.endswith(".doc"):
        return None
    # parent_directory=file_util.parent_directory(doc_path)
    docx_path=doc_path+"x"
    print("docx_path",docx_path)
    if not os.path.exists(docx_path):
        doc_to_docx(doc_path,docx_path)
    return read_docx(docx_path)
# doSaveAas()
# ————————————————
# 版权声明：本文为CSDN博主「m0_38074612」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。
# 原文链接：https://blog.csdn.net/m0_38074612/article/details/128985384
import docx


def read_docx(file_path):
    doc = docx.Document(file_path)
    content = []
    for para in doc.paragraphs:
        content.append(para.text)
    return "\n".join(content)